﻿using AllInOne.ModelDb;
using HY.Common;
using Newtonsoft.Json;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Growl = HandyControl.Controls.Growl;

using SmartExporter;

namespace AllInOne.Menu
{
    /// <summary>
    /// 发货单位与客户类型对应关系的设置
    /// </summary>
    [AddINotifyPropertyChangedInterface]
    public partial class ShowInfoWindow : Window
    {
        public ShowInfoWindow()
        {
            InitializeComponent();
            DataContext = this;
            string fileName = @"D:\Worktion\010_赤峰云铜\01Code\004自助机\测试\123.xlsx";
            //测试导入：
            ExportExcelHelper export = new ExportExcelHelper(fileName); 
            bool isFirstRowColumn = false;
            export.ExcelToDataTable(fileName, isFirstRowColumn);


        }
        //public ObservableCollection<VerifyPlateList> ModelList { get; set; }

        /// <summary>
        /// ---------------------------------------------ModelList
        /// </summary>
        public List<VerifyPlateList> ModelList { get; set; }


        public int DataSelectIndex { get; set; }

        public string SearchString { get; set; }

        public Visibility Loading { get; set; }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SearchList();
        }

        public void SearchClick(object sender, RoutedEventArgs e)
        {
            SearchList();
        }


        void SearchList()
        {
            try
            {
                string date = DateTime.Now.Date.ToString("yyyy-MM-dd");
                string goodsname = "铁粉";
                string msg = "";
                //QueryVerifyPlateList(string Date,string GoodsName,out string msg)
                List<VerifyPlateList> VerifyPlateList = ServiceWebApi.QueryVerifyPlateList(date, goodsname, out msg);
                ModelList = VerifyPlateList;
            }
            catch (Exception ex)
            {
            }
        }

        private void Delete(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("您是否确认删除此条信息？", "警告", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) == MessageBoxResult.Yes)
            {
                try
                {
                    //CustomBaseData model = ModelList[DataSelectIndex];
                    //string resultStr = HttpHelper.Post("Common/DeleteCustomBaseData", JsonConvert.SerializeObject(model));
                    //ReturnModel ret = JsonConvert.DeserializeObject<ReturnModel>(resultStr);
                    //if (ret.Code == 200)
                    //{
                    //    Growl.Info("删除成功");
                    //    ModelList.Remove(model);
                    //}
                    //else
                    //{
                    //    LogHelper.Info(ret.Message);
                    //    Growl.Warning("删除失败");
                    //}
                }
                catch (Exception ex)
                {
                    Growl.Warning("删除失败");
                    //LogHelper.Error(nameof(Delete), ex);
                }
            }
        }

        private void Add_Click(object sender, RoutedEventArgs e)
        {
            //CustomerTypeEdit win = new CustomerTypeEdit(new CustomBaseData() { BaseDataType="CustomerType"}, "新增");
            //win.Owner = Window.GetWindow(this);
            //win.ShowInTaskbar = false;
            //win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //if (win.ShowDialog() ?? false)
            //{
            //    ModelList.Insert(0, win.Model);
            //}
        }

        private void Update(object sender, RoutedEventArgs e)
        {
            //CustomBaseData model = ModelList[DataSelectIndex];
            //CustomerTypeEdit win = new CustomerTypeEdit(model, "修改");
            //win.Owner = Window.GetWindow(this);
            //win.ShowInTaskbar = false;
            //win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            //if (win.ShowDialog() ?? false)
            //{
            //    ModelList.Remove(model);
            //    ModelList.Insert(0, win.Model);
            //}
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
